
/**
 * @author lichenxi
 * @date 2020/4/8
 * 增广矩阵
 */
public class LinearSystem {

    //增广矩阵
    public Matrix abMatrix;

    public Matrix gaussJordanElimination(){
        return this.abMatrix.gaussJordanElimination();
    }

    /**
     * @param matrix 系数矩阵
     * @param vector 结果向量
     */
    LinearSystem(Matrix matrix,Vector vector){
        //矩阵的行必须等于向量的行
        if (matrix.rowNum()!=vector.getlen()){
            throw new RuntimeException("矩阵的列必须等于向量的列");
        }
        //目前矩阵必须是个方阵
        if (!Matrix.isSquMatrix(matrix)){
            throw new RuntimeException("目前矩阵必须是个方阵");
        }

        Vector[] vectors = new Vector[matrix.colNum()];
        //够贱增广矩阵
        for (int i = 0; i < matrix.rowNum(); i++) {
            Double[] doubles = new Double[matrix.colNum()+1];
            for (int j = 0; j < matrix.colNum(); j++) {
                doubles[j]=matrix.getItem(i,j);
            }
            doubles[doubles.length-1] = vector.getItem(i);
            vectors[i] = new Vector(doubles);
        }
        this.abMatrix = new Matrix(vectors,true);
    }
}
